package com.mfnote.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class RandomUtils {
	private static List<Integer> list = new ArrayList<Integer>();
	private  static int size = 100;
	static{
		for(int i= 0;i<size;i++){
			list.add(i);
		}
	}
	
	/**生成一个requestCode**/
    public static int getRequestCode(){
    	int requestCode = 0;
    	if(size<1){
    		return -1;
    	}
    	Random random = new Random();
    	int randomInt = random.nextInt(size);
    	requestCode = list.get(randomInt);
    	list.remove(randomInt);
    	size--;
    	return requestCode;
    }
    
    /**回收不再需要的requestCode**/
    public static void recycleRequestCode(int requestCode){
    	list.add(requestCode);
    	size++;
    }
}
